package com.tsingtree.modular.service.impl;

import com.tsingtree.modular.entity.MercRelation;
import com.tsingtree.modular.mapper.MercRelationMapper;
import com.tsingtree.modular.model.params.MercRelationParam;
import com.tsingtree.modular.model.result.MercRelationResult;
import  com.tsingtree.modular.service.MercRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import com.tsingtree.base.pojo.page.LayuiPageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tsingtree.base.pojo.page.LayuiPageFactory;
import com.tsingtree.roses.core.util.ToolUtil;
import java.io.Serializable;


/**
 * <p>
 * 角色和菜单关联表 服务实现类
 * </p>
 *
 * @author jagger
 * @since 2023-08-31
 */
@Service
public class MercRelationServiceImpl extends ServiceImpl<MercRelationMapper, MercRelation> implements MercRelationService {

    @Override
    public void add(MercRelationParam param){
        MercRelation entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(MercRelationParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(MercRelationParam param){
        MercRelation oldEntity = getOldEntity(param);
        MercRelation newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public MercRelationResult findBySpec(MercRelationParam param){
        return null;
    }

    @Override
    public List<MercRelationResult> findListBySpec(MercRelationParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(MercRelationParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(MercRelationParam param){
        return param.getRelationId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private MercRelation getOldEntity(MercRelationParam param) {
        return this.getById(getKey(param));
    }

    private MercRelation getEntity(MercRelationParam param) {
        MercRelation entity = new MercRelation();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
